// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    swipeList: [
      {text:"底妆口碑大赏", imgSrc:"https://static-cse.canva.cn/blob/312574/IMG_9198.jpg"},
      {text:"宣传水果", imgSrc:"https://img.shetu66.com/2023/07/11/1689037885708709.png"},
      {text:"双十一来袭", imgSrc:"https://static-cse.canva.cn/blob/26393/IMG_9197.jpg"}
    ]
  },

  onLoad: function(options) {
    // 页面加载时的逻辑
  },

  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  onChooseAvatar(e) {
    const { avatarUrl } = e.detail
    const { nickName } = this.data.userInfo
    this.setData({
      "userInfo.avatarUrl": avatarUrl,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },

  onInputChange(e) {
    const nickName = e.detail.value
    const { avatarUrl } = this.data.userInfo
    this.setData({
      "userInfo.nickName": nickName,
      hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
    })
  },

  getUserProfile(e) {
    wx.getUserProfile({
      desc: '展示用户信息',
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },

  // 跳转到调查问卷页面
  goToQuestionnaire: function() {
    console.log('进入goToQuestionnaire方法'); 
    console.log('1. 方法被调用');
  
    // 检查页面是否存在
    const app = getApp();
    console.log('2. 检查页面配置');
  
    wx.navigateTo({
      url: '/pages/questionnaire/questionnaire',
      success: function(res) {
        console.log('3. 跳转成功', res);
      },
      fail: function(err) {
        console.log('4. 跳转失败', err);
      }
    });
  },

  // 商品点击事件
  onProductTap: function(e) {
    const productId = e.currentTarget.dataset.id;
    console.log('点击了商品ID:', productId);
    
    // 跳转到商品详情页
    wx.navigateTo({
      url: '/pages/product/detail?id=' + productId
    });
  },

  // 加入购物车事件
  onAddToCart: function(e) {
    // 阻止事件冒泡
    e.stopPropagation();
    
    const productId = e.currentTarget.dataset.id;
    console.log('加入购物车商品ID:', productId);
    
    wx.showToast({
      title: '已加入购物车',
      icon: 'success'
    });
  },

  // 跳转到星座运势页面（合并到这里）
  goToFortunePage: function() {
    console.log('跳转到星座运势页面');
    wx.navigateTo({
      url: '/pages/fortune-page/fortune-page'
    })
  },
  // 🆕 新增的跳转到百度热搜页面函数
  goToBaiduHot: function() {
    console.log('跳转到百度热搜页面');
    wx.navigateTo({
      url: '/pages/baidu-hot/index'
    });
  },
  // 在现有跳转函数后面添加这个新函数
  goToPersonalPage: function() {
    console.log('跳转到个人主页');
    wx.navigateTo({
      url: '/pages/ydw/index'
    });
  }
})